//统一管理咱们项目用户相关的接口
import request from '@/utils/request'
import { AxiosResponse } from 'axios'
import qs from 'qs'
import { ExamPageQuery, ExamPageRes, ExamParams } from './type'

// 项目用户相关的请求地址
enum Exam_API {
  GET_EXAM_PAGE_BY_ADMIN = '/teaching_system/exam/more',
  GET_EXAM_PAGE_BY_STU = '/teaching_system/exam/more/stu',
  GET_EXAM_PAGE_BY_TEA = '/teaching_system/exam/more/tea',
  POST_PUT_EXAM_ONE = '/teaching_system/exam/one',
  DELETE_EXAM_BY_ID = '/teaching_system/exam/one/{id}',
}

/**
 * 管理员获取考试
 * @param {string} examPageQuery 考试分页请求对象
 * @returns
 */
export const reqGetAllExamByAdmin = (params: ExamPageQuery) =>
  request.get<any, AxiosResponse<ExamPageRes>>(
    Exam_API.GET_EXAM_PAGE_BY_ADMIN + '?' + qs.stringify(params),
  )

/**
 * 学生获取考试
 * @param {string} examPageQuery 考试分页请求对象
 * @returns
 */
export const reqGetExamByStu = (params: ExamPageQuery) =>
  request.get<any, AxiosResponse<ExamPageRes>>(
    Exam_API.GET_EXAM_PAGE_BY_STU + '?' + qs.stringify(params),
  )

/**
 * 老师获取考试
 * @param {string} examPageQuery 考试分页请求对象
 * @returns
 */
export const reqGetExamByTea = (params: ExamPageQuery) =>
  request.get<any, AxiosResponse<ExamPageRes>>(
    Exam_API.GET_EXAM_PAGE_BY_TEA + '?' + qs.stringify(params),
  )

/**
 * 添加考试
 * @param {object} params 新增考试表
 * @param {string} params.examName 考试名称
 * @param {number} params.courseId 课程ID
 * @param {object} params.examDate 考试日期
 * @param {number} params.duration 考试时长（分钟）
 * @param {string} params.location 考试地点
 * @param {string} params.description 考试描述
 * @returns
 */
export const reqAddExam = (params: ExamParams) =>
  request.post<any, AxiosResponse<any>>(Exam_API.POST_PUT_EXAM_ONE, params)

/**
 * 更新考试
 * @param {object} params 更新公示表
 * @param {number} params.examId 考试ID
 * @param {string} params.examName 考试名称
 * @param {number} params.courseId 课程ID
 * @param {object} params.examDate 考试日期
 * @param {number} params.duration 考试时长（分钟）
 * @param {string} params.location 考试地点
 * @param {string} params.description 考试描述
 * @returns
 */
export const reqUpdateExam = (params: ExamParams) =>
  request.put<any, AxiosResponse<any>>(Exam_API.POST_PUT_EXAM_ONE, params)

/**
 * id删除考试
 * @param {string} id
 * @returns
 */
export const reqDeleteExamById = (id: number) =>
  request.delete<any, AxiosResponse<any>>(
    Exam_API.DELETE_EXAM_BY_ID.replace('{id}', id.toString()),
  )
